<?php

namespace App\Http\Controllers\Frontend\Content;

use App\Http\Controllers\BaseController;
use App\Interfaces\CategoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CategoryController extends BaseController
{
    protected CategoryInterface $category;
    public function __construct(CategoryInterface $category)
    {
        $this->category = $category;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function getCategory(Request $request): JsonResponse
    {
        $tenantId = $request->headers->get('tenantId');
        $res = $this->category->getAllCategory($tenantId);
        if (!$res){
            return $this->apiResult(['code'=>1,'message'=>'暂无数据！']);
        }
        return $this->apiResult(['code'=>0,'data'=>$res,'message'=>'SUCCESS']);
    }

    public function getCateInfo(Request $request): JsonResponse
    {
        $cateId = $request->input('cateId');
        $res = $this->category->getCategory($cateId);
        if (!$res){
            return $this->apiResult(['code'=>1,'message'=>'暂无数据！']);
        }
        return $this->apiResult(['code'=>0,'data'=>$res,'message'=>'SUCCESS']);
    }
}
